//
// Created by ZLY on 2025/5/7.
//
#ifndef OBJECT_H
#define OBJECT_H

#include "game.h"
#include "defs.h"
#include <vector>

class Object {
protected:
    std::string id;
    ObjectType type_ = ObjectType::NONE; // 对象类型
    Game &game_ = Game::GetInstance(); // 获取游戏单例
    std::vector<Object *> object_to_add_;
    std::vector<Object *> children_; // 对象列表
    bool is_active_ = true; // 是否激活
    bool need_remove_ = false;

public:
    Object() = default;

    virtual ~Object() = default;

    virtual void init() {
    }

    virtual void update(float dt);

    virtual void render();

    virtual void clean();

    virtual bool handleEvents(SDL_Event &event); //false 则向下处理

    void safeAddChild(Object *child) { object_to_add_.push_back(child); }

    virtual void addChild(Object *child) // 添加子对象
    {
        children_.push_back(child);
    }

    virtual void removeChild(Object *child) // 移除子对象
    {
        children_.erase(std::remove(children_.begin(), children_.end(), child), children_.end());
    }

    [[nodiscard]] ObjectType getType() const { return type_; } // 获取对象类型
    void setType(const ObjectType type) { type_ = type; } // 设置对象类型
    void setActive(const bool is_active) { is_active_ = is_active; } // 设置对象是否激活
    [[nodiscard]] bool getActive() const { return is_active_; } // 获取对象是否激活
    void setNeedRemove(const bool is_need_remove) {
        need_remove_ = is_need_remove;
    }

    bool getNeedRemove() const { return need_remove_; }
};

#endif // OBJECT_H
